<?php 
require_once("model/loginBD.php");
function search_user_db($suser) {
	$query = "SELECT id_user, mail, civilite, nom, prenom FROM user
				WHERE id_user LIKE (\"%$suser%\")
				OR mail LIKE (\"%$suser%\")
				OR nom LIKE (\"%$suser%\")
				OR prenom LIKE (\"%$suser%\")"; 
								 
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		$i = 0;
		while($row = mysql_fetch_array($result)) {
			$tab['id_user'][$i] = $row['id_user'];
			$tab['mail'][$i] = $row['mail'];
			$tab['civilite'][$i] = $row['civilite'];
			$tab['nom'][$i] = $row['nom'];
			$tab['prenom'][$i] = $row['prenom'];
			++$i;
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

function search_category_db($scategory) {
	$query = "SELECT id_categ, name_categ, comment_categ FROM category
				WHERE id_categ LIKE (\"%$scategory%\")
				OR name_categ LIKE (\"%$scategory%\")
				OR comment_categ LIKE (\"%$scategory%\")";
								 
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		$i = 0;
		while($row = mysql_fetch_array($result)) {
			$tab['id_categ'][$i] = $row['id_categ'];
			$tab['name_categ'][$i] = $row['name_categ'];
			$tab['comment_categ'][$i] = $row['comment_categ'];
			++$i;
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

function search_forum_db($sforum) {
	$query = "SELECT id_forum, id_user, id_categ, text_forum, date_forum FROM forum
				WHERE id_forum LIKE (\"%$sforum%\")
				OR id_user LIKE (\"%$sforum%\")
				OR id_categ LIKE (\"%$sforum%\")
				OR text_forum LIKE (\"%$sforum%\")"; 
								 
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		$i = 0;
		while($row = mysql_fetch_array($result)) {
			$tab['id_forum'][$i] = $row['id_forum'];
			$tab['id_user_forum'][$i] = $row['id_user'];
			$tab['id_categ_forum'][$i] = $row['id_categ'];
			$tab['text_forum'][$i] = $row['text_forum'];
			$tab['date_forum'][$i] = $row['date_forum'];
			++$i;
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

function search_skill_db($sskill) {
	$query = "SELECT id_skill, name_skill FROM skills
				WHERE id_skill LIKE (\"%$sskill%\")
				OR name_skill LIKE (\"%$sskill%\")"; 
								 
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		$i = 0;
		while($row = mysql_fetch_array($result)) {
			$tab['id_skill'][$i] = $row['id_skill'];
			$tab['name_skill'][$i] = $row['name_skill'];
			++$i;
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

?>